package com.cysion.study.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.cysion.study.R
import com.cysion.study.entity.FamilyeduCelcrsEntity
import com.cysion.study.ktbox.base.BaseAdapter
import com.cysion.study.ktbox.base.BaseViewHolder
import com.cysion.study.ktbox.base.ITEM_CLICK
import com.cysion.study.widget.ShowToast
import com.cysion.study.widget.TvChannelItem
import kotlinx.android.synthetic.main.item_course_detail_p.view.*
import kotlinx.android.synthetic.main.item_coursedetail_p.view.*

class PCourseDetailAdapter(mEntities: MutableList<FamilyeduCelcrsEntity>, mContext: Context) :
    BaseAdapter<FamilyeduCelcrsEntity>(mEntities, mContext) {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder<FamilyeduCelcrsEntity> {

        return ProMoneyHolder(
            LayoutInflater.from(mContext).inflate(R.layout.item_course_detail_p, parent, false)
//            LayoutInflater.from(mContext).inflate(R.layout.item_coursedetail_p, parent, false)
        )
    }
    class ProMoneyHolder(itemView: View) : BaseViewHolder<FamilyeduCelcrsEntity>(itemView) {
        override fun fillData(obj: FamilyeduCelcrsEntity, position: Int) {
            itemView?.apply {
//                itemView.item_tv_channel.setChannel(obj)
                itemView.tv_time.setText(obj.startTimeStr)
                itemView.tv_num.setText(obj.crsNum)
                //status":1//状态：1、待确认；2、家长拒绝；3、家长同意；4、系统自动同意；5、教师撤销
                //status":1//状态：1、待确认；2、家长拒绝；3、家长同意；4、系统自动同意；5、教师撤销
                if (obj.status == "1") {
                    itemView.tv_status.setText("待确认")
                    itemView.iv_more.visibility=View.VISIBLE
                } else if (obj.status == "2") {
                    itemView.tv_status.setText("家长拒绝")
                    itemView.iv_more.visibility=View.GONE
                } else if (obj.status == "3") {
                    itemView.tv_status.setText("已消课")
                    itemView.iv_more.visibility=View.GONE
                } else if (obj.status == "4") {
                    itemView.tv_status.setText("系统自动同意")
                    itemView.iv_more.visibility=View.GONE
                } else if (obj.status == "5") {
                    itemView.tv_status.setText("教师撤销")
                    itemView.iv_more.visibility=View.GONE
                }

                /*itemView.item_tv_channel.setOnItemClickListener(object : TvChannelItem.OnIemClick {
                    override fun onItemDetailClick(type: Int) {
                        mOnTypeClickListener?.invoke(obj, position, type)
                    }

                })*/
                var isShow=1
                itemView.iv_more.setOnClickListener {
                    if (obj.status == "5") {
                        ShowToast("此课时已撤销")
                        return@setOnClickListener
                    }
                    if (isShow == 1) {
                        tv_week.visibility = View.VISIBLE
                        tv_cancel.visibility = View.VISIBLE
                        isShow = 0
                    } else {
                        tv_week.visibility = View.GONE
                        tv_cancel.visibility = View.GONE
                        isShow = 1
                    }

                }


                itemView.tv_week.setOnClickListener {

                    mOnTypeClickListener?.invoke(obj, position, 1)//1提醒，2撤销
                    tv_week.visibility = View.GONE
                    tv_cancel.visibility = View.GONE
                    isShow = 1
                }
                itemView.tv_cancel.setOnClickListener {
                    mOnTypeClickListener?.invoke(obj, position, 2)//1提醒，2撤销
                    tv_week.visibility = View.GONE
                    tv_cancel.visibility = View.GONE
                    isShow = 1
                }
                /*itemView.setOnClickListener {
                    mOnTypeClickListener?.invoke(obj, position, ITEM_CLICK)
                }*/

            }

        }

    }

}



